<?php

namespace App\Services\Cache;

use App\Models\Moment;
use Illuminate\Support\Facades\Cache;
use App\Http\Controllers\Api\V1\Queries\CommentQuery;

class MomentCache
{
	
	public function moments($isAttention)
	{
		$key = url()->full();
		$moments = Cache::remember($key, 1, function () use ($isAttention) {
			if($isAttention){
				$ids = request()->user()->attentions->pluck('attention_user_id');
				$moments = Moment::query()->whereIn('user_id',$ids)->orderByDesc("id")->paginate();
			}else{
				$moments = Moment::query()->orderByDesc("id")->paginate();
			}
			
			return $moments;
		});
		return $moments;
	}
}
